package com.example.truthordare;

import java.util.ArrayList;
import java.util.Collections;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;

public class MathScore extends Activity {
	int round = 1;
	int x;
	String z;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_math_score);
		TextView txwin = (TextView) findViewById(R.id.mathscore_win);
		ListView lv = (ListView) findViewById(R.id.mathScore_listView1);
		TextView tvround = (TextView) findViewById(R.id.mathscore_round);
		Button btconti = (Button) findViewById(R.id.mathScore_tb1);
		Bundle recivebd = this.getIntent().getExtras();
		if (recivebd != null) {
			round = recivebd.getInt("round");
		}
		tvround.setText("Round " + round + " of 10 is over");
		z = findwin();
		txwin.setText(z + " is win");
		PlaygameAdapter playadp = new PlaygameAdapter(this, DataTranfer
				.getInstance().getList());
		lv.setAdapter(playadp);
		btconti.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				round++;
				Bundle sendBundle = new Bundle();
				sendBundle.putInt("round", round);
				sendBundle.putString("name", z);
				Intent i = new Intent();
				i.putExtras(sendBundle);
				setResult(RESULT_OK, i);
				finish();
			}
		});
	}

	public String findwin() {

		int n = DataTranfer.getInstance().getList().size();
		int max = DataTranfer.getInstance().getList().get(0).getSroce();
		String z = DataTranfer.getInstance().getList().get(0).getPlayer();
		for (x = 0; x < n; x++) {
			if (max < DataTranfer.getInstance().getList().get(x).getSroce()) {
				max = DataTranfer.getInstance().getList().get(x).getSroce();
				z = DataTranfer.getInstance().getList().get(x).getPlayer();
			}
		}
		return z;

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.math_score, menu);
		return true;
	}

}
